package com.oracle.lingshangejia.activity;

import android.app.DatePickerDialog;
import android.content.Intent;
import android.database.Cursor;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.afollestad.materialdialogs.MaterialDialog;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.oracle.lingshangejia.Constant;
import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.adapter.ArchivesExtendableListAdapter;
import com.oracle.lingshangejia.base.BaseActivity;
import com.oracle.lingshangejia.bean.DataBean;
import com.oracle.lingshangejia.bean.FormulateBean;
import com.oracle.lingshangejia.bean.IdCardBean;
import com.oracle.lingshangejia.dialog.ArchivesTypeFormulateDialog;
import com.oracle.lingshangejia.utils.AppManagerDelegate;
import com.oracle.lingshangejia.utils.ArchivesSQLiteHelper;
import com.oracle.lingshangejia.utils.LastClickUtils;
import com.oracle.lingshangejia.utils.MyLogger;
import com.oracle.lingshangejia.utils.MyToast;
import com.oracle.lingshangejia.utils.OkHttpUtils;
import com.oracle.lingshangejia.utils.SpUtils;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ArchivesActivity extends BaseActivity implements OnClickListener {
    private ExpandableListView expandableListView;
    private ArchivesExtendableListAdapter archivesExtendableListAdapter;
    private ArchivesSQLiteHelper sqLiteHelper;
    private TextView tv_title;
    private ImageButton ib_back;
    private String id_number;//身份证号
    private List<String> committeeIds = new ArrayList<>();
    private List<String> mList; //居委会

    // 获取居委会下拉列表信息
    private void loadCommittee() {
        String uri = Constant.baseurl + "online/jwhList";
        OkGo.getInstance().init(getApplication());
        JSONObject params = new JSONObject();
        try {
            String token = (String) SpUtils.get(ArchivesActivity.this, "token", "");
            int mark= (int) SpUtils.get(ArchivesActivity.this,"mark",1);
            int userId = (int) SpUtils.get(ArchivesActivity.this,"ysid",1);
            params.put("token",token);
            params.put("userId",userId);
            params.put("mark",mark);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        OkGo.<String>post(uri)
                .upJson(params.toString())
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String body = response.body();
                        System.out.println(body);
                        mList = new ArrayList<>();
                        try {
                            JSONObject jsonObject = new JSONObject(body);
                            JSONArray jsonArray = jsonObject.getJSONArray("data");
                            for(int i = 0; i < jsonArray.length(); i++) {
                                JSONObject object = jsonArray.getJSONObject(i);
                                String name = object.getString("name");
                                String xqId = object.getString("xqId");
                                committeeIds.add(xqId);
                                mList.add(name);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        Spinner spinner = findViewById(R.id.archives_committee);
                        spinner.setAdapter(new ArrayAdapter<>(ArchivesActivity.this,android.R.layout.simple_spinner_dropdown_item, mList));
                    }

                    @Override
                    public void onError(Response<String> response) {
                        Toast.makeText(getApplicationContext(), "服务器暂时无法访问，稍后再试！", Toast.LENGTH_LONG).show();
                        //System.exit(0);
                    }
                });
    }

    //检查手机号是否注册
    private void checkPhone(String phone){
        HashMap<Object,Object> map = new HashMap<>();
        map.put("brdh",phone);
        OkHttpUtils.getNetWork(ArchivesActivity.this, Constant.checkPhone,map,phonehandler);

    }
    //手机号
    private Handler phonehandler=new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case 1:  //成功S
                    String s= (String) msg.obj;
                    Gson gson=new Gson();
                    DataBean bean=gson.fromJson(s,DataBean.class );
                    if (bean.getMsg().equals("手机号已存在")){
                        MyToast.show("手机号已注册");
                    }else {
                        getNetIdentify(id_number);
                    }

                    break;
                case 2: //连接上服务器，错误
                    String error= (String) msg.obj;
                    Toast.makeText(ArchivesActivity.this,error,Toast.LENGTH_SHORT).show();
                    break;
                case 3:  //没有网络
                    Toast.makeText(ArchivesActivity.this,"网络不可用",Toast.LENGTH_SHORT).show();
                    break;
                case 4: //没有连接上服务器
                    Toast.makeText(ArchivesActivity.this,"连接服务器失败",Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    };

    /**
     * 检查用户名、身份证号和本人联系电话是否正确填写
     *
     * @return 数据不正确返回true，正确返回false
     */
    private boolean checkBasicInfoIsError() {
        Map<String, String> basicInforValues = getBasicInfoValues();
        String xm = (String) basicInforValues.get("xm");
        String sfzh = (String) basicInforValues.get("sfzh");
        String brdh = (String) basicInforValues.get("brdh");
        // 姓名非空验证
        if (xm == null || xm.length() == 0) {
            Toast.makeText(getApplicationContext(), "姓名必须填写", Toast.LENGTH_SHORT).show();
            return true;
        }
        if ( mType.equals("2")){
            if (TextUtils.isEmpty(mSelectFormulate)){
                MyToast.show("请选择则制定服务包");
            }

        }
         //居委会
        if(committeeIds.size() == 0){
            MyToast.show("请完善居委会信息 否则无法添加个人信息");
            return true;
        }
        // 身份证非空验证
        if (sfzh == null || sfzh.length() == 0) {
            Toast.makeText(getApplicationContext(), "身份证号必须填写", Toast.LENGTH_SHORT).show();
            return true;
        }
        // 验证身份证号格式
        String idCardRegex = "^([1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx])|([1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2})$";
        if (!sfzh.matches(idCardRegex)) {
            Toast.makeText(getApplicationContext(), "身份证号格式不正确", Toast.LENGTH_SHORT).show();
            return true;
        }

        // 本人电话非空验证
        if (brdh == null || brdh.length() == 0) {
            Toast.makeText(getApplicationContext(), "本人电话必须填写", Toast.LENGTH_SHORT).show();
            return true;
        }
        // 本人电话号码格式验证
        String selfPhoneRegex = "^1[34578]\\d{9}$";
        if (!brdh.matches(selfPhoneRegex)) {
            Toast.makeText(getApplicationContext(), "本人电话格式不正确", Toast.LENGTH_SHORT).show();
            return true;
        }
        // 联系人电话号码格式验证
        String lxrdh = (String) basicInforValues.get("lxrdh");
        if (lxrdh != null && lxrdh.length() > 0 && !lxrdh.matches(selfPhoneRegex)) {
            Toast.makeText(getApplicationContext(), "联系人电话格式不正确", Toast.LENGTH_SHORT).show();
            return true;
        }
        mPhone = brdh;
        return false;
    }
    private String mPhone ;

    /**
     * Activity销毁时清空SQLite中数据
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        sqLiteHelper.deleteAll();
    }

    @Override
    public int intiLayout() {
        return R.layout.add_archives_activity;
    }

    @Override
    public void initView() {
        tv_title=findViewById(R.id.tv_title);
        tv_title.setText("个人基本信息");
        ib_back=findViewById(R.id.ib_back);
        ib_back.setOnClickListener(this);
        expandableListView = findViewById(R.id.expend_list);
        String[] archivesStr = getResources().getStringArray(R.array.archives);
        archivesExtendableListAdapter = new ArchivesExtendableListAdapter(archivesStr);
        expandableListView.setAdapter(archivesExtendableListAdapter);
        // 添加末尾提交按钮
        View foot = LayoutInflater.from(this).inflate(R.layout.childrenarchives_foot_submit, null);
        expandableListView.addFooterView(foot);

        expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                return checkBasicInfoIsError();
            }
        });

        expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
            @Override
            public void onGroupExpand(int groupPosition) {
                int count = expandableListView.getExpandableListAdapter().getGroupCount();
                for (int i = 0; i < count; i++) {
                    if (i != groupPosition) {
                        expandableListView.collapseGroup(i);
                    }
                }
            }
        });
        expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
            @Override
            public void onGroupCollapse(int groupPosition) {
                View[] views = ((ArchivesExtendableListAdapter) expandableListView.getExpandableListAdapter()).getConvertViews();
                View view = views[groupPosition];
                if (view == null) {
                    return;
                }
                Map<String, String> values = null;
                switch (groupPosition) {
                    case 0:
                        values = getBasicInfoValues();
                        break;
                    case 1:
                        values = getEducationAndProfessionalAndMarriageAndPayValues(view);
                        break;
                    case 2:
                        values = getAllergyAndExposedValues(view);
                        break;
                    case 3:
                        values = getDiseaseValues(view);
                        break;
                    case 4:
                        values = getSurgeryAndTraumaAndTransfusionValues(view);
                        break;
                    case 5:
                        values = getFamilialDiseaseFatherValues(view);
                        break;
                    case 6:
                        values = getFamilialDiseaseMotherValues(view);
                        break;
                    case 7:
                        values = getFamilialDiseaseBrotherValues(view);
                        break;
                    case 8:
                        values = getFamilialDiseaseChildrenValues(view);
                        break;
                    case 9:
                        values = getGeneticDiseaseAndDisabilityAndEnvironmentValues(view);
                        break;
                }
                System.out.println("数据：" + values);
                if (values != null && values.size() > 0)
                    saveValues(values);

            }
        });
        expandableListView.expandGroup(1);
        expandableListView.collapseGroup(0);

        expandableListView.expandGroup(0);
        archivesExtendableListAdapter.notifyDataSetChanged();
        expandableListView.setSelection(0);
        loadCommittee();
        sqLiteHelper = new ArchivesSQLiteHelper(this);
        sqLiteHelper.onUpgrade(sqLiteHelper.getReadableDatabase(),1,1);

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        getBasicInfoValues();
                    }
                });
            }
        }).start();

    }

    @Override
    public void initData() {

    }

    /**
     * 存储临时数据到SQLite
     * @param values
     */
    private void saveValues(Map<String, String> values) {
        String sfzh = (String) getBasicInfoValues().get("sfzh");
        Cursor cursor = sqLiteHelper.queryByIdCard(new String[]{sfzh});
        if (cursor.getCount() == 0) {
            sqLiteHelper.insert(values);
        } else {
            sqLiteHelper.update(values, sfzh);
        }
    }

    //签约类型默认 普惠
    private String mType = "1";
    /**
     * 获取基本信息数据
     */
    private int sfqy; //是否签约
    private Map<String, String> getBasicInfoValues() {
        View[] views = ((ArchivesExtendableListAdapter) expandableListView.getExpandableListAdapter()).getConvertViews();
        View view = views[0];
        if(view ==null)
            return null;
        Map<String, String> params = new HashMap<>();
        // 姓名
        String username = "";
        // 居委会
        int committeePosition;
        // 编号
        //String number = "";
        // 性别
        String gender = "";
        // 出生日期
        String birthday = "";
        // 身份证
        String idCard = "";
        // 工作单位
        String workUnits = "";
        // 本人电话
        String selfPhone = "";
        // 联系人
        String linkman = "";
        // 联系人电话
        String linkmanPhone = "";
        // 民族
        String national = "";
        // 常住类型
        String permanent = "";
        // 血型
        String bloodType = "";
        String bloodHR = "";
        String name = "";
        String sex="";
        String number="";
        String imageId = "";
        String censusRegisteAddress ="";//户籍地址
        String address ="";
        if(getIntent()!=null){
            name=getIntent().getStringExtra("shebao_name");
            sex=getIntent().getStringExtra("shebao_sex");
            number=getIntent().getStringExtra("shebao_number");
            birthday =getIntent().getStringExtra("birthday");
            imageId =getIntent().getStringExtra("image");
            sfqy = getIntent().getIntExtra("sfqy",0);

            Log.e("number",number+"身份证");
            if(!TextUtils.isEmpty(number)){
                if(((EditText) view.findViewById(R.id.archives_idCard)).getText().toString().trim().length() ==0)
                ((EditText) view.findViewById(R.id.archives_idCard)).setText(number);
            }
            if("男".equals(sex)){
                ((Spinner) view.findViewById(R.id.archives_gender)).setSelection(0,true);
            }else{
                ((Spinner) view.findViewById(R.id.archives_gender)).setSelection(1,true);
            }
           // ((Spinner) view.findViewById(R.id.archives_gender)).setEnabled(false);// 设置性别不可点击

            if(!TextUtils.isEmpty(name)){
                if(((EditText) view.findViewById(R.id.archives_username)).getText().toString().trim().length() ==0)
                    ((EditText) view.findViewById(R.id.archives_username)).setText(name);
            }
            if (!TextUtils.isEmpty(birthday)){
                StringBuffer stringBuffer = new StringBuffer(birthday);
                stringBuffer.insert(4,"-" );
                stringBuffer.insert(7,"-" );
                ((TextView)view.findViewById(R.id.archives_birthday)).setText(stringBuffer);
            }
            ((EditText) view.findViewById(R.id.archives_username)).setHint(birthday);
        }
        username = ((EditText) view.findViewById(R.id.archives_username)).getText().toString().trim();
        committeePosition = ((Spinner) view.findViewById(R.id.archives_committee)).getSelectedItemPosition();
        //number = ((EditText) view.findViewById(R.id.archives_number)).getText().toString().trim();
        gender = ((Spinner) view.findViewById(R.id.archives_gender)).getSelectedItem().toString().trim();
        gender = gender.substring(0, gender.indexOf(" "));
        birthday = ((TextView) view.findViewById(R.id.archives_birthday)).getText().toString().trim();
        idCard = ((EditText) view.findViewById(R.id.archives_idCard)).getText().toString().trim();
        workUnits = ((EditText) view.findViewById(R.id.archives_workUnits)).getText().toString().trim();
        selfPhone = ((EditText) view.findViewById(R.id.archives_self_phone)).getText().toString().trim();
        linkman = ((EditText) view.findViewById(R.id.archives_linkman)).getText().toString().trim();
        linkmanPhone = ((EditText) view.findViewById(R.id.archives_linkman_phone)).getText().toString().trim();

        censusRegisteAddress = ((EditText) view.findViewById(R.id.census_registe_address)).getText().toString();
        address = ((EditText) view.findViewById(R.id.address)).getText().toString();
        TextView nation = view.findViewById(R.id.tv_nation);
        String s = nation.getText().toString(); //获取民族字符串
        int i = s.lastIndexOf(" ");// 查找空 将数字截取出来
        national = s.substring(0,i);//
        /*if (((RadioButton) view.findViewById(R.id.archives_national_han)).isChecked()) {
            //national = "1 汉族";
            national = "1";
        } else {
            //national = ((EditText) views[0].findViewById(R.id.archives_national_other)).getText().toString().trim();
            national = "99";
        }*/
        birthday = birthday +" 00:00:00";
        permanent = ((Spinner) view.findViewById(R.id.archives_permanent)).getSelectedItem().toString().trim();
        permanent = permanent.substring(0, permanent.indexOf(" "));
        bloodType = ((Spinner) view.findViewById(R.id.archives_bloodType)).getSelectedItem().toString().trim();
        bloodType = bloodType.substring(0, bloodType.indexOf(" "));
        bloodHR = ((Spinner) view.findViewById(R.id.archives_bloodHR)).getSelectedItem().toString().trim();
        bloodHR = bloodHR.substring(0, bloodHR.indexOf(" "));
        params.put("xm", username);
        if(committeeIds.size() == 0) {
            //params.put("xqid", Integer.toString(1));
        } else {
            params.put("xqid", committeeIds.get(committeePosition));
        }
        id_number=idCard;
        params.put("hjdz", censusRegisteAddress);//户籍地址
        params.put("xzz", address);//现地址

        params.put("sczp", imageId);//手持身份证id
        params.put("dzb", mSelectFormulate);
        params.put("fwlb", mType);//服务包
        params.put("xb", gender);//性别
        params.put("csrq", birthday);//出生日期
        params.put("sfzh", idCard);//身份id
        params.put("gzdw", workUnits);//工作单位
        params.put("brdh", selfPhone);//本人电话
        params.put("lxrxm", linkman);//联系人姓名
        params.put("lxrdh", linkmanPhone);//联系人电话
        params.put("czlx", permanent);//常住类型
        params.put("mz", national); //民族
        params.put("xx", bloodType);//血型
        params.put("yx", bloodHR);//hr 阴阳

        return params;
    }

    /**
     * 获取文化、职业、婚姻、支付方式信息数据
     */
    private Map<String, String> getEducationAndProfessionalAndMarriageAndPayValues(View view) {
        Map<String, String> params = new HashMap<>();
        // 文化
        String education = "";
        // 职业
        String professional = "";
        // 婚姻
        String marriage = "";
        // 支付方式
        String pay = "";
        // 支付方式其它
        String otherPay = "";
        education = ((Spinner) view.findViewById(R.id.archives_education)).getSelectedItem().toString().trim();
        education = education.substring(0, education.indexOf(" "));
        professional = ((Spinner) view.findViewById(R.id.archives_professional)).getSelectedItem().toString().trim();
        professional = professional.substring(0, professional.indexOf(" "));
        marriage = ((Spinner) view.findViewById(R.id.archives_marriage)).getSelectedItem().toString().trim();
        marriage = marriage.substring(0, marriage.indexOf(" "));
        View[] payViews = getViews(view.findViewById(R.id.archives_pay));
        for (int i = 0; i < payViews.length; i++) {
            if (payViews[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) payViews[i];
                if (cb.isChecked()) {
                    String s = cb.getText().toString().trim();
                    s = s.substring(0, s.indexOf(" "));
                    pay += s;
                    pay += ",";
                }
            }
        }
        if (pay.length() != 0) {
            pay = pay.substring(0, pay.length() - 1);
        }
        otherPay = ((EditText) view.findViewById(R.id.archives_pay_other_text)).getText().toString().trim();

        params.put("whcd", education);
        params.put("zy", professional);
        params.put("hyzk", marriage);
        params.put("ylfyzffs", pay);
        params.put("ylfyzffs_qt", otherPay);
        return params;
    }

    /**
     * 获取药物过敏史、暴露史数据
     */
    private Map<String, String> getAllergyAndExposedValues(View view) {
        Map<String, String> params = new HashMap<>();
        // 药物过敏史
        String allergy = "";
        String otherAllergy = "";
        TableLayout table = ((TableLayout) view.findViewById(R.id.archives_allergy));
        View[] cbs = getViews(table);
        for (int i = 0; i < cbs.length; i++) {
            if (cbs[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) cbs[i];
                if (cb.isChecked()) {
                    String s = cb.getText().toString().trim();
                    s = s.substring(0, s.indexOf(" "));
                    allergy += s;
                    allergy += ",";
                }
            }
        }
        if (allergy.length() != 0) {
            allergy = allergy.substring(0, allergy.length() - 1);
        }
        otherAllergy = ((EditText) view.findViewById(R.id.archives_allergy_other_text)).getText().toString().trim();
        /*CheckBox checkBox =  view.findViewById(R.id.archives_allergy_none);//获取有无状态
        if (checkBox.isChecked()){
            allergy = "2";
        }else {
            allergy = "1,"+allergy;//1代表有疾病
        }*/
        params.put("ywgms", allergy);
        params.put("ywgms_qt", otherAllergy);

        // 暴露史
        String exposed = "";
        View[] exposedViews = getViews(view.findViewById(R.id.archives_exposed));
        for (int i = 0; i < exposedViews.length; i++) {
            if (exposedViews[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) exposedViews[i];
                if (cb.isChecked()) {
                    String s = cb.getText().toString().trim();
                    s = s.substring(0, s.indexOf(" "));
                    exposed += s;
                    exposed += ",";
                }
            }
        }
        if (exposed.length() != 0) {
            exposed = exposed.substring(0, exposed.length() - 1);
        }
       /* CheckBox checkBox1 =  view.findViewById(R.id.archives_exposed_none);//获取有无状态
        if (checkBox1.isChecked()){
            exposed = "2";
        }else {
            exposed = "1,"+exposed;//1代表有疾病
        }*/
        params.put("bls", exposed);
        return params;
    }

    /**
     * 获取疾病史数据
     */
    private Map<String, String> getDiseaseValues(View view) {
        Map<String, String> params = new HashMap<>();
        String disease = "";
        String diseaseHypertension = "";
        String diseaseHypertensionDate = "";
        String diseaseDiabetes = "";
        String diseaseDiabetesDate = "";
        String diseaseHeart = "";
        String diseaseHeartDate = "";
        String diseaseLung = "";
        String diseaseLungDate = "";
        String diseaseCancer = "";
        String diseaseCancerDate = "";
        String diseaseCancerName = "";
        String diseaseStroke = "";
        String diseaseStrokeDate = "";
        String diseasePsychosis = "";
        String diseasePsychosisDate = "";
        String diseaseTB = "";
        String diseaseTBDate = "";
        String diseaseHepatitis = "";
        String diseaseHepatitisDate = "";
        String diseaseInfectious = "";
        String diseaseInfectiousDate = "";
        String diseaseOccupational = "";
        String diseaseOccupationalDate = "";
        String diseaseOccupationalName = "";
        String diseaseOther = "";
        String diseaseOtherDate = "";
        /*View[] diseaseViews = getViews(view.findViewById(R.id.archives_disease));
        for (int i = 0; i < diseaseViews.length; i++) {
            if (diseaseViews[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) diseaseViews[i];
                if (cb.isChecked()) {
                    String s = cb.getText().toString().trim();
                    s = s.substring(0, s.indexOf(" "));
                    disease += s;
                    disease += ",";
                }
            }
        }
        if (disease.length() != 0) {
            disease = disease.substring(0, disease.length() - 1);
        }*/

        diseaseHypertension = ((CheckBox) view.findViewById(R.id.archives_disease_hypertension)).getText().toString().trim();
        diseaseHypertensionDate = ((TextView) view.findViewById(R.id.archives_disease_hypertension_date)).getText().toString().trim();
        diseaseDiabetes = ((CheckBox) view.findViewById(R.id.archives_disease_diabetes)).getText().toString().trim();
        diseaseDiabetesDate = ((TextView) view.findViewById(R.id.archives_disease_diabetes_date)).getText().toString().trim();
        diseaseHeart = ((CheckBox) view.findViewById(R.id.archives_disease_heart)).getText().toString().trim();
        diseaseHeartDate = ((TextView) view.findViewById(R.id.archives_disease_heart_date)).getText().toString().trim();
        diseaseLung = ((CheckBox) view.findViewById(R.id.archives_disease_lung)).getText().toString().trim();
        diseaseLungDate = ((TextView) view.findViewById(R.id.archives_disease_lung_date)).getText().toString().trim();
        diseaseCancer = ((CheckBox) view.findViewById(R.id.archives_disease_cancer)).getText().toString().trim();
        diseaseCancerDate = ((TextView) view.findViewById(R.id.archives_disease_cancer_date)).getText().toString().trim();
        diseaseCancerName = ((TextView) view.findViewById(R.id.archives_disease_cancer_location)).getText().toString().trim();
        diseaseStroke = ((CheckBox) view.findViewById(R.id.archives_disease_stroke)).getText().toString().trim();
        diseaseStrokeDate = ((TextView) view.findViewById(R.id.archives_disease_stroke_date)).getText().toString().trim();
        diseasePsychosis = ((CheckBox) view.findViewById(R.id.archives_disease_psychosis)).getText().toString().trim();
        diseasePsychosisDate = ((TextView) view.findViewById(R.id.archives_disease_psychosis_date)).getText().toString().trim();
        diseaseTB = ((CheckBox) view.findViewById(R.id.archives_disease_tb)).getText().toString().trim();
        diseaseTBDate = ((TextView) view.findViewById(R.id.archives_disease_tb_date)).getText().toString().trim();
        diseaseHepatitis = ((CheckBox) view.findViewById(R.id.archives_disease_hepatitis)).getText().toString().trim();
        diseaseHepatitisDate = ((TextView) view.findViewById(R.id.archives_disease_hepatitis_date)).getText().toString().trim();
        diseaseInfectious = ((CheckBox) view.findViewById(R.id.archives_disease_infectious)).getText().toString().trim();
        diseaseInfectiousDate = ((TextView) view.findViewById(R.id.archives_disease_infectious_date)).getText().toString().trim();
        diseaseOccupational = ((CheckBox) view.findViewById(R.id.archives_disease_occupational)).getText().toString().trim();
        diseaseOccupationalDate = ((TextView) view.findViewById(R.id.archives_disease_occupational_date)).getText().toString().trim();
        diseaseOccupationalName = ((TextView) view.findViewById(R.id.archives_disease_occupational_location)).getText().toString().trim();
        diseaseOther = ((CheckBox) view.findViewById(R.id.archives_disease_other)).getText().toString().trim();
        diseaseOtherDate = ((TextView) view.findViewById(R.id.archives_disease_other_date)).getText().toString().trim();
        CheckBox jb = ((CheckBox) view.findViewById(R.id.archives_disease_none));//获取疾病控件
        if (jb.isChecked()){//知否有疾病 1有 2无
            disease = "1";
        }else {
            disease = "2";
        }
        // 高血压
        CheckBox hypertension = view.findViewById(R.id.archives_disease_hypertension);
        if (hypertension.isChecked()){
            diseaseHypertension ="1";
        }else {
            diseaseHypertension ="2";
        }
        // 糖尿病
        CheckBox diabetes = view.findViewById(R.id.archives_disease_diabetes);
        if (diabetes.isChecked()){
            diseaseDiabetes = "1";
        }else {
            diseaseDiabetes = "2";
        }
        // 冠心病
        CheckBox heart = view.findViewById(R.id.archives_disease_heart);
        if(heart.isChecked()){
            diseaseHeart = "1";
        }else {
            diseaseHeart = "2";
        }
        // 慢性阻塞性肺疾病
        CheckBox lung = view.findViewById(R.id.archives_disease_lung);
        if (lung.isChecked()){
            diseaseLung = "1";
        }else {
            diseaseLung = "2";
        }

        // 恶性肿瘤
        CheckBox cancer = view.findViewById(R.id.archives_disease_cancer);
        if (cancer.isChecked()){
            diseaseCancer = "1";
        }else {
            diseaseCancer = "2";
        }
        // 脑卒中
        CheckBox stroke = view.findViewById(R.id.archives_disease_stroke);
       if (stroke.isChecked()){
           diseaseStroke = "1";
       }else {
           diseaseStroke = "2";
       }
        // 严重精神障碍
        CheckBox psychosis = view.findViewById(R.id.archives_disease_psychosis);
        if (psychosis.isChecked()){
            diseasePsychosis = "1";
        }else {
           diseasePsychosis = "2";
        }
        // 结核病
        CheckBox tb = view.findViewById(R.id.archives_disease_tb);
        if (tb.isChecked()){
            diseaseTB = "1";
        }else {
            diseaseTB = "2";
        }
        // 肝炎
        CheckBox hepatitis = view.findViewById(R.id.archives_disease_hepatitis);
        if (hepatitis.isChecked()){
            diseaseHepatitis = "1";
        }else {
            diseaseHepatitis = "2";
        }
        // 其他法定传染病
        CheckBox infectious = view.findViewById(R.id.archives_disease_infectious);
        if (infectious.isChecked()){
            diseaseInfectious = "1";
        }else {
            diseaseInfectious = "2";
        }
        // 职业病
        CheckBox occupational = view.findViewById(R.id.archives_disease_occupational);
        if (occupational.isChecked()) {
           diseaseOccupational = "1";
        }else {
            diseaseOccupational = "2";
        }
        // 其它
        CheckBox other = view.findViewById(R.id.archives_disease_other);
        if (other.isChecked()){
            diseaseOther = "1";
        }else {
            diseaseOther = "2";
        }

        params.put("jb", disease); //
        params.put("jb_gxy", diseaseHypertension);//高血压
        params.put("jb_gxy_qzsj", diseaseHypertensionDate);//高血压时间
        params.put("jb_tnb", diseaseDiabetes);      //糖尿病
        params.put("jb_tnb_qzsj", diseaseDiabetesDate);//糖尿病时间
        params.put("jb_gxb", diseaseHeart);             //冠心病
        params.put("jb_gxb_qzsj", diseaseHeartDate);
        params.put("jb_mxzsxfjb", diseaseLung);    //慢性柱塞性肺疾病
        params.put("jb_mxzsxfjb_qzsj", diseaseLungDate);
        params.put("jb_exzl", diseaseCancer);     //恶性肿瘤
        params.put("jb_exzl_qzsj", diseaseCancerDate);
        params.put("jb_exzl_wz", diseaseCancerName);//位置
        params.put("jb_ncz", diseaseStroke);   // 脑卒中
        params.put("jb_ncz_qzsj", diseaseStrokeDate);
        params.put("jb_yzjsza", diseasePsychosis);//严重精神病
        params.put("jb_yzjsza_qzsj", diseasePsychosisDate);
        params.put("jb_jhb", diseaseTB);          //结核病
        params.put("jb_jhb_qzsj", diseaseTBDate);
        params.put("jb_gy", diseaseHepatitis);
        params.put("jb_gy_qzsj", diseaseHepatitisDate);
        params.put("jb_qtfdcrb", diseaseInfectious);
        params.put("jb_qtfdcrb_qzsj", diseaseInfectiousDate);
        params.put("jb_zyb", diseaseOccupational);
        params.put("jb_zyb_qzsj", diseaseOccupationalDate);//职业病
        params.put("jb_zyb_wz", diseaseOccupationalName);//职业病位置
        params.put("jb_qt", diseaseOther);
        params.put("jb_qt_qzsj", diseaseOtherDate);
        return params;
    }

    /**
     * 获取手术、外伤、输血数据
     */
    private Map<String, String> getSurgeryAndTraumaAndTransfusionValues(View view) {
        Map<String, String> params = new HashMap<>();
        // 手术
        String archivesSurgery = "";
        String archivesSurgeryOne = "";
        String archivesSurgeryOneDate = "";
        String archivesSurgeryTwo = "";
        String archivesSurgeryTwoDate = "";
        if (view != null) {
            RadioButton none = view.findViewById(R.id.archives_surgery_none);
            RadioButton all = view.findViewById(R.id.archives_surgery_all);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                archivesSurgery = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                archivesSurgery = s;
            }
            archivesSurgeryOne = ((EditText) view.findViewById(R.id.archives_surgery_all_1_name)).getText().toString().trim();
            archivesSurgeryOneDate = ((TextView) view.findViewById(R.id.archives_surgery_all_1_date)).getText().toString().trim();
            archivesSurgeryTwo = ((EditText) view.findViewById(R.id.archives_surgery_all_2_name)).getText().toString().trim();
            archivesSurgeryTwoDate = ((TextView) view.findViewById(R.id.archives_surgery_all_2_date)).getText().toString().trim();
        }


        /*RadioButton button = view.findViewById(R.id.archives_surgery_none);
        //获取有无状态
        if (button.isChecked()){
            archivesSurgery = "2";
        }else {
            archivesSurgery = "1";
        }*/
        params.put("ss", archivesSurgery);  //手术 有无选项
        params.put("ss_mc1", archivesSurgeryOne);//手术名称
        params.put("ss_sj1", archivesSurgeryOneDate);//时间
        params.put("ss_mc2", archivesSurgeryTwo);//名称
        params.put("ss_sj2", archivesSurgeryTwoDate);//时间

        // 外伤
        String trauma = "";
        String traumaOne = "";
        String traumaOneDate = "";
        String traumaTwo = "";
        String traumaTwoDate = "";
        if (view != null) {
            RadioButton none = view.findViewById(R.id.archives_trauma_none);
            RadioButton all = view.findViewById(R.id.archives_trauma_all);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                trauma = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                trauma = s;
            }
            traumaOne = ((EditText) view.findViewById(R.id.archives_trauma_all_1_name)).getText().toString().trim();
            traumaOneDate = ((TextView) view.findViewById(R.id.archives_trauma_all_1_date)).getText().toString().trim();
            traumaTwo = ((EditText) view.findViewById(R.id.archives_trauma_all_2_name)).getText().toString().trim();
            traumaTwoDate = ((TextView) view.findViewById(R.id.archives_trauma_all_2_date)).getText().toString().trim();
        }
        /*RadioButton button1 = view.findViewById(R.id.archives_trauma_none);
        //获取有无状态
        if (button1.isChecked()){
            trauma = "2";
        }else {
            trauma = "1";
        }*/
        params.put("ws", trauma);// 外伤  有无
        params.put("ws_mc1", traumaOne);// 名称
        params.put("ws_sj1", traumaOneDate);//时间
        params.put("ws_mc2", traumaTwo);//
        params.put("ws_sj2", traumaTwoDate);//

        // 第五页，输血
        String transfusion = "";
        String transfusionOne = "";
        String transfusionOneDate = "";
        String transfusionTwo = "";
        String transfusionTwoDate = "";
        if (view != null) {
            RadioButton none = view.findViewById(R.id.archives_transfusion_none);
            RadioButton all = view.findViewById(R.id.archives_transfusion_all);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                transfusion = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                transfusion = s;
            }
            transfusionOne = ((EditText) view.findViewById(R.id.archives_transfusion_all_1_name)).getText().toString().trim();
            transfusionOneDate = ((TextView) view.findViewById(R.id.archives_transfusion_all_1_date)).getText().toString().trim();
            transfusionTwo = ((EditText) view.findViewById(R.id.archives_transfusion_all_2_name)).getText().toString().trim();
            transfusionTwoDate = ((TextView) view.findViewById(R.id.archives_transfusion_all_2_date)).getText().toString().trim();
        }
        /*RadioButton button2 = view.findViewById(R.id.archives_transfusion_none);
        //获取有无状态
        if (button2.isChecked()){
            transfusion = "2";
        }else {
            transfusion = "1";
        }*/
        params.put("sx", transfusion);///输血  有无
        params.put("sx_yy1", transfusionOne);
        params.put("sx_sj1", transfusionOneDate);
        params.put("sx_yy2", transfusionTwo);
        params.put("sx_sj2", transfusionTwoDate);
        return params;
    }

    /**
     * 获取家族病史（父亲）数据
     */
    private Map<String, String> getFamilialDiseaseFatherValues(View view) {
        Map<String, String> params = new HashMap<>();
        String familialDiseaseFather = "";
        String familialDiseaseFatherOther = "";
        if (view != null) {
            View[] familialDiseaseFatherViews = getViews(view.findViewById(R.id.archives_familial_disease_father));
            for (int i = 0; i < familialDiseaseFatherViews.length; i++) {
                if (familialDiseaseFatherViews[i] instanceof CheckBox) {
                    CheckBox cb = (CheckBox) familialDiseaseFatherViews[i];
                    if (cb.isChecked()) {
                        String s = cb.getText().toString().trim();
                        s = s.substring(0, s.indexOf(" "));
                        familialDiseaseFather += s;
                        familialDiseaseFather += ",";
                    }
                }
            }
            if (familialDiseaseFather.length() != 0) {
                familialDiseaseFather = familialDiseaseFather.substring(0, familialDiseaseFather.length() - 1);
            }
            familialDiseaseFatherOther = ((EditText) view.findViewById(R.id.archives_familial_disease_father_other_text)).getText().toString().trim();
        }
        /*CheckBox checkBox =  view.findViewById(R.id.archives_familial_disease_father_none);//获取有无状态
        if (checkBox.isChecked()){
            familialDiseaseFather = "2";
        }else {
            familialDiseaseFather = "1,"+familialDiseaseFather;
        }*/
        params.put("jzs_fq", familialDiseaseFather);
        params.put("jzs_fq_qt", familialDiseaseFatherOther);
        return params;
    }

    /**
     * 获取家族病史（母亲）数据
     */
    private Map<String, String> getFamilialDiseaseMotherValues(View view) {
        Map<String, String> params = new HashMap<>();
        String familialDiseaseMother = "";
        String familialDiseaseMotherOther = "";
        if (view != null) {
            View[] familialDiseaseMotherViews = getViews(view.findViewById(R.id.archives_familial_disease_mother));
            for (int i = 0; i < familialDiseaseMotherViews.length; i++) {
                if (familialDiseaseMotherViews[i] instanceof CheckBox) {
                    CheckBox cb = (CheckBox) familialDiseaseMotherViews[i];
                    if (cb.isChecked()) {
                        String s = cb.getText().toString().trim();
                        s = s.substring(0, s.indexOf(" "));
                        familialDiseaseMother += s;
                        familialDiseaseMother += ",";
                    }
                }
            }
            if (familialDiseaseMother.length() != 0) {
                familialDiseaseMother = familialDiseaseMother.substring(0, familialDiseaseMother.length() - 1);
            }
            familialDiseaseMotherOther = ((EditText) view.findViewById(R.id.archives_familial_disease_mother_other_text)).getText().toString().trim();
        }

    /*    CheckBox checkBox =  view.findViewById(R.id.archives_familial_disease_mother_none);//获取有无状态
        if (checkBox.isChecked()){
            familialDiseaseMother = "2";
        }else {
            familialDiseaseMother = "1,"+familialDiseaseMother;//1代表有疾病
        }*/
        params.put("jzs_mq", familialDiseaseMother);
        params.put("jzs_mq_qt", familialDiseaseMotherOther);//疾病名称

        return params;
    }

    /**
     * 获取家族病史（兄弟）数据
     */
    private Map<String, String> getFamilialDiseaseBrotherValues(View view) {
        Map<String, String> params = new HashMap<>();
        String familialDiseaseBrother = "";
        String familialDiseaseBrotherOther = "";
        if (view != null) {
            View[] familialDiseaseBrotherViews = getViews(view.findViewById(R.id.archives_familial_disease_brother));
            for (int i = 0; i < familialDiseaseBrotherViews.length; i++) {
                if (familialDiseaseBrotherViews[i] instanceof CheckBox) {
                    CheckBox cb = (CheckBox) familialDiseaseBrotherViews[i];
                    if (cb.isChecked()) {
                        String s = cb.getText().toString().trim();
                        s = s.substring(0, s.indexOf(" "));
                        familialDiseaseBrother += s;
                        familialDiseaseBrother += ",";
                    }
                }
            }
            if (familialDiseaseBrother.length() != 0) {
                familialDiseaseBrother = familialDiseaseBrother.substring(0, familialDiseaseBrother.length() - 1);
            }
            familialDiseaseBrotherOther = ((EditText) view.findViewById(R.id.archives_familial_disease_brother_other_text)).getText().toString().trim();
        }
        /*CheckBox checkBox =  view.findViewById(R.id.archives_familial_disease_brother_none);//获取有无状态
        if (checkBox.isChecked()){
            familialDiseaseBrother = "2";
        }else {
            familialDiseaseBrother = "1,"+familialDiseaseBrother;//1代表有疾病
        }*/
        params.put("jzs_xdjm", familialDiseaseBrother);
        params.put("jzs_xdjm_qt", familialDiseaseBrotherOther);
        return params;
    }

    /**
     * 获取家族病史（子女）数据
     */
    private Map<String, String> getFamilialDiseaseChildrenValues(View view) {
        Map<String, String> params = new HashMap<>();
        String familialDiseaseChildren = "";
        String familialDiseaseChildrenOther = "";
        if (view != null) {
            View[] familialDiseaseChildrenViews = getViews(view.findViewById(R.id.archives_familial_disease_children));
            for (int i = 0; i < familialDiseaseChildrenViews.length; i++) {
                if (familialDiseaseChildrenViews[i] instanceof CheckBox) {
                    CheckBox cb = (CheckBox) familialDiseaseChildrenViews[i];
                    if (cb.isChecked()) {
                        String s = cb.getText().toString().trim();
                        s = s.substring(0, s.indexOf(" "));
                        familialDiseaseChildren += s;
                        familialDiseaseChildren += ",";
                    }
                }
            }
            if (familialDiseaseChildren.length() != 0) {
                familialDiseaseChildren = familialDiseaseChildren.substring(0, familialDiseaseChildren.length() - 1);
            }
            familialDiseaseChildrenOther = ((EditText) view.findViewById(R.id.archives_familial_disease_children_other_text)).getText().toString().trim();
        }

       /* CheckBox checkBox =  view.findViewById(R.id.archives_familial_disease_children_none);//获取有无状态
        if (checkBox.isChecked()){
            familialDiseaseChildren = "2";
        }else {
            familialDiseaseChildren = "1,"+familialDiseaseChildren;//1代表有疾病
        }
*/
        params.put("jzs_zn", familialDiseaseChildren);
        params.put("jzs_zn_qt", familialDiseaseChildrenOther);
        return params;
    }

    /**
     * 获取遗传病史、残疾情况、生活环境数据
     */
    private Map<String, String> getGeneticDiseaseAndDisabilityAndEnvironmentValues(View view) {
        Map<String, String> params = new HashMap<>();
        // 遗传病史
        String genetic = "";
        String geneticName = "";
        if (view != null) {
            RadioButton none = view.findViewById(R.id.archives_genetic_disease_none);
            RadioButton all = view.findViewById(R.id.archives_genetic_disease_all);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                genetic = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                genetic = s;
            }
            geneticName = ((EditText) view.findViewById(R.id.archives_genetic_disease_all_name)).getText().toString().trim();
        }
       /* RadioButton checkBox =  view.findViewById(R.id.archives_genetic_disease_none);
        if (checkBox.isChecked()){
            genetic = "2";
        }else {
            genetic = "1";
        }*/

        params.put("ycbs", genetic);
        params.put("ycbs_jbmc", geneticName);

        // 残疾情况
        String disability = "";
        String otherDisability = "";
        if (view != null) {
            View[] disabilityViews = getViews(view.findViewById(R.id.archives_disability));
            for (int i = 0; i < disabilityViews.length; i++) {
                if (disabilityViews[i] instanceof CheckBox) {
                    CheckBox cb = (CheckBox) disabilityViews[i];
                    if (cb.isChecked()) {
                        String s = cb.getText().toString().trim();
                        s = s.substring(0, s.indexOf(" "));
                        disability += s;
                        disability += ",";
                    }
                }
            }
            if (disability.length() != 0) {
                disability = disability.substring(0, disability.length() - 1);
            }
            otherDisability = ((EditText) view.findViewById(R.id.archives_disability_other_text)).getText().toString().trim();

        }

        /*CheckBox checkBo =  view.findViewById(R.id.archives_disability_none);//获取有无状态
        if (checkBo.isChecked()){
            disability = "2";
        }else {
            disability= "1,"+disability;//1代表有疾病
        }
*/
        params.put("cjqk", disability);
        params.put("cjqk_qtcj", otherDisability);

        // 生活环境
        String kitchenExhaust = "";
        String fuelType = "";
        String water = "";
        String toilet = "";
        String livestockBar = "";
        if (view != null) {
            kitchenExhaust = ((Spinner) view.findViewById(R.id.archives_kitchen_exhaust)).getSelectedItem().toString().trim();
            kitchenExhaust = kitchenExhaust.substring(0, kitchenExhaust.indexOf(" "));
            fuelType = ((Spinner) view.findViewById(R.id.archives_fuel_type)).getSelectedItem().toString().trim();
            fuelType = fuelType.substring(0, fuelType.indexOf(" "));
            water = ((Spinner) view.findViewById(R.id.archives_water)).getSelectedItem().toString().trim();
            water = water.substring(0, water.indexOf(" "));
            toilet = ((Spinner) view.findViewById(R.id.archives_toilet)).getSelectedItem().toString().trim();
            toilet = toilet.substring(0, toilet.indexOf(" "));
            livestockBar = ((Spinner) view.findViewById(R.id.archives_livestock_bar)).getSelectedItem().toString().trim();
            livestockBar = livestockBar.substring(0, livestockBar.indexOf(" "));
        }
        params.put("cfpfss", kitchenExhaust);
        params.put("rllx", fuelType);
        params.put("rs", water);
        params.put("cs", toilet);
        params.put("qcl", livestockBar);
        return params;
    }


    /**
     * Toolbar的事件---返回
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * 点击日期选择框弹出DatePickerDialog
     */
    private Calendar calendar;
    private DatePickerDialog dialog;

    public void onTimeViewClick(final View v) {
        calendar = Calendar.getInstance();
        dialog = new DatePickerDialog(ArchivesActivity.this,
                new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year,
                                          int monthOfYear, int dayOfMonth) {
                        TextView tv = (TextView) v;
                        String month;
                        String day;
                        if (monthOfYear <9){
                            month = "0"+(monthOfYear+1);
                        }else {
                            month = ""+(monthOfYear+1);
                        }
                        if (dayOfMonth <10){
                            day = "0"+dayOfMonth;
                        }else {
                            day = dayOfMonth + "";
                        }
                        tv.setText(year + "-" + month  + "-" + day);
                    }
                }, calendar.get(Calendar.YEAR), calendar
                .get(Calendar.MONTH), calendar
                .get(Calendar.DAY_OF_MONTH));
        dialog.show();
    }

    /**
     * "民族"按钮点击事件处理
     */
   /* public void changeNationalEnableEdit(View view) {
        //EditText ed = findViewById(R.id.archives_national_other);
        RadioButton rb = (RadioButton) view;
      *//*  if (view.getId() == R.id.archives_national_han) {
            ed.setText("");
            ed.setEnabled(false);
        } else if (rb.isChecked()) {
            ed.setEnabled(true);
            ed.setFocusable(true);
            ed.setFocusableInTouchMode(true);
            ed.requestFocus();
        }*//*
    }*/

    //选择的签约制定id
    private String mSelectFormulate ="";

    //签约类型
    public void changeNationalEnableType(View view) {
        mSelectFormulate ="";
        if ( view.getId() == R.id.rb_type){
             mType = "1";//普惠
        }else {

            ArchivesTypeFormulateDialog archivesTypeFormulateDialog = new ArchivesTypeFormulateDialog();
            archivesTypeFormulateDialog.setListener(new ArchivesTypeFormulateDialog.Listener() {
                @Override
                public void select(List<FormulateBean.DataBean> list) {
                    if (list !=null){

                         for (FormulateBean.DataBean dataBean:list){
                                mSelectFormulate += dataBean.getId()+",";

                         }

                        mSelectFormulate = mSelectFormulate.substring(0,mSelectFormulate.length() - 1);
                        MyToast.show("选择了"+list.size()+"项");
                    }else {
                        MyToast.show("没有选择");
                    }
                }
            });
            archivesTypeFormulateDialog.show(getSupportFragmentManager(),null );
            mType = "2";//制定
        }


    }

    /**
     * 其它支付按钮点击事件
     */
    public void onPayOtherClick(View view) {
        CheckBox cb = (CheckBox) view;
        EditText et = findViewById(R.id.archives_pay_other_text);
        if (cb.isChecked()) {
            et.setEnabled(true);
            et.setFocusable(true);
            et.setFocusableInTouchMode(true);
            et.requestFocus();
        } else {
            et.setText("");
            et.setEnabled(false);
        }
    }

    /**
     * 药物过敏史点击事件
     */
    public void onAllergyClick(View view) {
        View[] views = getViews(findViewById(R.id.archives_allergy));
        CheckBox none = findViewById(R.id.archives_allergy_none);
        CheckBox other = findViewById(R.id.archives_allergy_other);
        EditText otherText = findViewById(R.id.archives_allergy_other_text);
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view == none) {
                    if (none.isChecked() && cb != view) {
                        cb.setChecked(false);
                        otherText.setText("");
                        otherText.setEnabled(false);
                    }
                } else {
                    CheckBox v = (CheckBox) view;
                    if (v.isChecked()) {
                        none.setChecked(false);
                    }
                }
            }
        }
        if (flag != true) {
            none.setChecked(true);
        }
        if (other.isChecked()) {
            otherText.setEnabled(true);
            otherText.setFocusable(true);
            otherText.setFocusableInTouchMode(true);
            otherText.requestFocus();
        } else {
            otherText.setEnabled(false);
            otherText.setText("");
        }
    }

    /**
     * 暴露史点击事件
     */
    public void onExposedClick(View view) {
        View[] views = getViews(findViewById(R.id.archives_exposed));
        CheckBox none = findViewById(R.id.archives_exposed_none);
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view == none) {
                    if (none.isChecked() && cb != none) {
                        cb.setChecked(false);
                    }
                } else {
                    CheckBox v = (CheckBox) view;
                    if (v.isChecked()) {
                        none.setChecked(false);
                    }
                }
            }
        }
        if (flag != true) {
            none.setChecked(true);
        }
    }

    /**
     * 疾病史按钮点击事件
     */
    public void onDiseaseClick(View view) {
        // 五
        CheckBox none = findViewById(R.id.archives_disease_none);
        // 高血压
        CheckBox hypertension = findViewById(R.id.archives_disease_hypertension);
        TextView hypertensionDate = findViewById(R.id.archives_disease_hypertension_date);
        // 糖尿病
        CheckBox diabetes = findViewById(R.id.archives_disease_diabetes);
        TextView diabetesDate = findViewById(R.id.archives_disease_diabetes_date);
        // 冠心病
        CheckBox heart = findViewById(R.id.archives_disease_heart);
        TextView heartDate = findViewById(R.id.archives_disease_heart_date);
        // 慢性阻塞性肺疾病
        CheckBox lung = findViewById(R.id.archives_disease_lung);
        TextView lungDate = findViewById(R.id.archives_disease_lung_date);
        // 恶性肿瘤
        CheckBox cancer = findViewById(R.id.archives_disease_cancer);
        TextView cancerDate = findViewById(R.id.archives_disease_cancer_date);
        EditText cancerLocation = findViewById(R.id.archives_disease_cancer_location);
        // 脑卒中
        CheckBox stroke = findViewById(R.id.archives_disease_stroke);
        TextView strokDate = findViewById(R.id.archives_disease_stroke_date);
        // 严重精神障碍
        CheckBox psychosis = findViewById(R.id.archives_disease_psychosis);
        TextView psychosisDate = findViewById(R.id.archives_disease_psychosis_date);
        // 结核病
        CheckBox tb = findViewById(R.id.archives_disease_tb);
        TextView tbDate = findViewById(R.id.archives_disease_tb_date);
        // 肝炎
        CheckBox hepatitis = findViewById(R.id.archives_disease_hepatitis);
        TextView hepatitisDate = findViewById(R.id.archives_disease_hepatitis_date);
        // 其他法定传染病
        CheckBox infectious = findViewById(R.id.archives_disease_infectious);
        TextView infectiousDate = findViewById(R.id.archives_disease_infectious_date);
        // 职业病
        CheckBox occupational = findViewById(R.id.archives_disease_occupational);
        TextView occupationalDate = findViewById(R.id.archives_disease_occupational_date);
        EditText occupationalLocation = findViewById(R.id.archives_disease_occupational_location);
        // 其它
        CheckBox other = findViewById(R.id.archives_disease_other);
        TextView otherDate = findViewById(R.id.archives_disease_other_date);
        switch (view.getId()) {
            case R.id.archives_disease_none:
                if (none.isChecked()) {
                    // 高血压
                    hypertension.setChecked(false);
                    hypertensionDate.setHint("年/月/日");
                    hypertensionDate.setEnabled(false);
                    // 糖尿病
                    diabetes.setChecked(false);
                    diabetesDate.setHint("年/月/日");
                    diabetesDate.setEnabled(false);
                    // 冠心病
                    heart.setChecked(false);
                    heartDate.setHint("年/月/日");
                    heartDate.setEnabled(false);
                    // 慢性阻塞性肺疾病
                    lung.setChecked(false);
                    lungDate.setHint("年/月/日");
                    lungDate.setEnabled(false);
                    // 恶性肿瘤
                    cancer.setChecked(false);
                    cancerDate.setHint("年/月/日");
                    cancerDate.setEnabled(false);
                    cancerLocation.setText("");
                    cancerLocation.setEnabled(false);
                    // 脑卒中
                    stroke.setChecked(false);
                    strokDate.setHint("年/月/日");
                    strokDate.setEnabled(false);
                    // 严重精神障碍
                    psychosis.setChecked(false);
                    psychosisDate.setHint("年/月/日");
                    psychosisDate.setEnabled(false);
                    // 结核病
                    tb.setChecked(false);
                    tbDate.setHint("年/月/日");
                    tbDate.setEnabled(false);
                    // 肝炎
                    hepatitis.setChecked(false);
                    hepatitisDate.setHint("年/月/日");
                    hepatitisDate.setEnabled(false);
                    // 其他法定传染病
                    infectious.setChecked(false);
                    infectiousDate.setHint("年/月/日");
                    infectiousDate.setEnabled(false);
                    // 职业病
                    occupational.setChecked(false);
                    occupationalDate.setHint("年/月/日");
                    occupationalDate.setEnabled(false);
                    occupationalLocation.setText("");
                    occupationalLocation.setEnabled(false);
                    // 其它
                    other.setChecked(false);
                    otherDate.setHint("年/月/日");
                    otherDate.setEnabled(false);
                } else {
                    none.setChecked(true);
                }
                break;
            case R.id.archives_disease_hypertension:
                none.setChecked(false);
                if (hypertension.isChecked()) {
                    hypertensionDate.setEnabled(true);
                } else {
                    hypertensionDate.setEnabled(false);
                    hypertensionDate.setHint("年/月/日");
                    if (!hypertension.isChecked() && !diabetes.isChecked()
                            && !heart.isChecked() && !lung.isChecked()
                            && !cancer.isChecked() && !stroke.isChecked()
                            && !psychosis.isChecked() && !tb.isChecked()
                            && !hepatitis.isChecked() && !infectious.isChecked()
                            && !occupational.isChecked() && !other.isChecked()) {
                        none.setChecked(true);
                    }
                }
                break;
            case R.id.archives_disease_diabetes:
                none.setChecked(false);
                if (diabetes.isChecked()) {
                    diabetesDate.setEnabled(true);
                } else {
                    diabetesDate.setEnabled(false);
                    diabetesDate.setHint("年/月/日");
                    if (!hypertension.isChecked() && !diabetes.isChecked()
                            && !heart.isChecked() && !lung.isChecked()
                            && !cancer.isChecked() && !stroke.isChecked()
                            && !psychosis.isChecked() && !tb.isChecked()
                            && !hepatitis.isChecked() && !infectious.isChecked()
                            && !occupational.isChecked() && !other.isChecked()) {
                        none.setChecked(true);
                    }
                }
                break;
            case R.id.archives_disease_heart:
                none.setChecked(false);
                if (heart.isChecked()) {
                    heartDate.setEnabled(true);
                } else {
                    heartDate.setEnabled(false);
                    heartDate.setHint("年/月/日");
                    if (!hypertension.isChecked() && !diabetes.isChecked()
                            && !heart.isChecked() && !lung.isChecked()
                            && !cancer.isChecked() && !stroke.isChecked()
                            && !psychosis.isChecked() && !tb.isChecked()
                            && !hepatitis.isChecked() && !infectious.isChecked()
                            && !occupational.isChecked() && !other.isChecked()) {
                        none.setChecked(true);
                    }
                }
                break;
            case R.id.archives_disease_lung:
                none.setChecked(false);
                if (lung.isChecked()) {
                    lungDate.setEnabled(true);
                } else {
                    lungDate.setEnabled(false);
                    lungDate.setHint("年/月/日");
                    if (!hypertension.isChecked() && !diabetes.isChecked()
                            && !heart.isChecked() && !lung.isChecked()
                            && !cancer.isChecked() && !stroke.isChecked()
                            && !psychosis.isChecked() && !tb.isChecked()
                            && !hepatitis.isChecked() && !infectious.isChecked()
                            && !occupational.isChecked() && !other.isChecked()) {
                        none.setChecked(true);
                    }
                }
                break;
            case R.id.archives_disease_cancer:
                none.setChecked(false);
                if (cancer.isChecked()) {
                    cancerDate.setEnabled(true);
                    cancerLocation.setEnabled(true);
                    cancerLocation.setFocusable(true);
                    cancerLocation.setFocusableInTouchMode(true);
                    cancerLocation.requestFocus();
                } else {
                    cancerDate.setEnabled(false);
                    cancerLocation.setEnabled(false);
                    cancerDate.setHint("年/月/日");
                    cancerLocation.setText("");
                    if (!hypertension.isChecked() && !diabetes.isChecked()
                            && !heart.isChecked() && !lung.isChecked()
                            && !cancer.isChecked() && !stroke.isChecked()
                            && !psychosis.isChecked() && !tb.isChecked()
                            && !hepatitis.isChecked() && !infectious.isChecked()
                            && !occupational.isChecked() && !other.isChecked()) {
                        none.setChecked(true);
                    }
                }
                break;
            case R.id.archives_disease_stroke:
                none.setChecked(false);
                if (stroke.isChecked()) {
                    strokDate.setEnabled(true);
                } else {
                    strokDate.setEnabled(false);
                    strokDate.setHint("年/月/日");
                    if (!hypertension.isChecked() && !diabetes.isChecked()
                            && !heart.isChecked() && !lung.isChecked()
                            && !cancer.isChecked() && !stroke.isChecked()
                            && !psychosis.isChecked() && !tb.isChecked()
                            && !hepatitis.isChecked() && !infectious.isChecked()
                            && !occupational.isChecked() && !other.isChecked()) {
                        none.setChecked(true);
                    }
                }
                break;
            case R.id.archives_disease_psychosis:
                none.setChecked(false);
                if (psychosis.isChecked()) {
                    psychosisDate.setEnabled(true);
                } else {
                    psychosisDate.setEnabled(false);
                    psychosisDate.setHint("年/月/日");
                    if (!hypertension.isChecked() && !diabetes.isChecked()
                            && !heart.isChecked() && !lung.isChecked()
                            && !cancer.isChecked() && !stroke.isChecked()
                            && !psychosis.isChecked() && !tb.isChecked()
                            && !hepatitis.isChecked() && !infectious.isChecked()
                            && !occupational.isChecked() && !other.isChecked()) {
                        none.setChecked(true);
                    }
                }
                break;
            case R.id.archives_disease_tb:
                none.setChecked(false);
                if (tb.isChecked()) {
                    tbDate.setEnabled(true);
                } else {
                    tbDate.setEnabled(false);
                    tbDate.setHint("年/月/日");
                    if (!hypertension.isChecked() && !diabetes.isChecked()
                            && !heart.isChecked() && !lung.isChecked()
                            && !cancer.isChecked() && !stroke.isChecked()
                            && !psychosis.isChecked() && !tb.isChecked()
                            && !hepatitis.isChecked() && !infectious.isChecked()
                            && !occupational.isChecked() && !other.isChecked()) {
                        none.setChecked(true);
                    }
                }
                break;
            case R.id.archives_disease_hepatitis:
                none.setChecked(false);
                if (hepatitis.isChecked()) {
                    hepatitisDate.setEnabled(true);
                } else {
                    hepatitisDate.setEnabled(false);
                    hepatitisDate.setHint("年/月/日");
                    if (!hypertension.isChecked() && !diabetes.isChecked()
                            && !heart.isChecked() && !lung.isChecked()
                            && !cancer.isChecked() && !stroke.isChecked()
                            && !psychosis.isChecked() && !tb.isChecked()
                            && !hepatitis.isChecked() && !infectious.isChecked()
                            && !occupational.isChecked() && !other.isChecked()) {
                        none.setChecked(true);
                    }
                }
                break;
            case R.id.archives_disease_infectious:
                none.setChecked(false);
                if (infectious.isChecked()) {
                    infectiousDate.setEnabled(true);
                } else {
                    infectiousDate.setEnabled(false);
                    infectiousDate.setHint("年/月/日");
                    if (!hypertension.isChecked() && !diabetes.isChecked()
                            && !heart.isChecked() && !lung.isChecked()
                            && !cancer.isChecked() && !stroke.isChecked()
                            && !psychosis.isChecked() && !tb.isChecked()
                            && !hepatitis.isChecked() && !infectious.isChecked()
                            && !occupational.isChecked() && !other.isChecked()) {
                        none.setChecked(true);
                    }
                }
                break;
            case R.id.archives_disease_occupational:
                none.setChecked(false);
                if (occupational.isChecked()) {
                    occupationalDate.setEnabled(true);
                    occupationalLocation.setEnabled(true);
                    occupationalLocation.setFocusable(true);
                    occupationalLocation.setFocusableInTouchMode(true);
                    occupationalLocation.requestFocus();
                } else {
                    occupationalDate.setEnabled(false);
                    occupationalLocation.setEnabled(false);
                    occupationalDate.setHint("年/月/日");
                    occupationalLocation.setText("");
                    if (!hypertension.isChecked() && !diabetes.isChecked()
                            && !heart.isChecked() && !lung.isChecked()
                            && !cancer.isChecked() && !stroke.isChecked()
                            && !psychosis.isChecked() && !tb.isChecked()
                            && !hepatitis.isChecked() && !infectious.isChecked()
                            && !occupational.isChecked() && !other.isChecked()) {
                        none.setChecked(true);
                    }
                }
                break;
            case R.id.archives_disease_other:
                none.setChecked(false);
                if (other.isChecked()) {
                    otherDate.setEnabled(true);
                } else {
                    otherDate.setEnabled(false);
                    otherDate.setHint("年/月/日");
                    if (!hypertension.isChecked() && !diabetes.isChecked()
                            && !heart.isChecked() && !lung.isChecked()
                            && !cancer.isChecked() && !stroke.isChecked()
                            && !psychosis.isChecked() && !tb.isChecked()
                            && !hepatitis.isChecked() && !infectious.isChecked()
                            && !occupational.isChecked() && !other.isChecked()) {
                        none.setChecked(true);
                    }
                }
                break;
        }
    }

    /**
     * 手术史按钮点击事件
     */
    public void onSurgeryClick(View view) {
        EditText et1 = findViewById(R.id.archives_surgery_all_1_name);
        TextView tv1 = findViewById(R.id.archives_surgery_all_1_date);
        EditText et2 = findViewById(R.id.archives_surgery_all_2_name);
        TextView tv2 = findViewById(R.id.archives_surgery_all_2_date);
        if (view.getId() == R.id.archives_surgery_none) {
            et1.setText("");
            tv1.setHint("手术时间");
            et2.setText("");
            tv2.setHint("手术时间");
            et1.setEnabled(false);
            tv1.setEnabled(false);
            et2.setEnabled(false);
            tv2.setEnabled(false);
        } else {
            et1.setEnabled(true);
            tv1.setEnabled(true);
            et2.setEnabled(true);
            tv2.setEnabled(true);
            et1.setFocusable(true);
            et1.setFocusableInTouchMode(true);
            et1.requestFocus();
        }
    }

    /**
     * 外伤史按钮点击事件
     */
    public void onTraumaClick(View view) {
        EditText et1 = findViewById(R.id.archives_trauma_all_1_name);
        TextView tv1 = findViewById(R.id.archives_trauma_all_1_date);
        EditText et2 = findViewById(R.id.archives_trauma_all_2_name);
        TextView tv2 = findViewById(R.id.archives_trauma_all_2_date);
        if (view.getId() == R.id.archives_trauma_none) {
            et1.setText("");
            tv1.setHint("外伤时间");
            et2.setText("");
            tv2.setHint("外伤时间");
            et1.setEnabled(false);
            tv1.setEnabled(false);
            et2.setEnabled(false);
            tv2.setEnabled(false);
        } else {
            et1.setEnabled(true);
            tv1.setEnabled(true);
            et2.setEnabled(true);
            tv2.setEnabled(true);
            et1.setFocusable(true);
            et1.setFocusableInTouchMode(true);
            et1.requestFocus();
        }
    }

    /**
     * 输血史按钮点击事件
     */
    public void onTransfusionClick(View view) {
        EditText et1 = findViewById(R.id.archives_transfusion_all_1_name);
        TextView tv1 = findViewById(R.id.archives_transfusion_all_1_date);
        EditText et2 = findViewById(R.id.archives_transfusion_all_2_name);
        TextView tv2 = findViewById(R.id.archives_transfusion_all_2_date);
        if (view.getId() == R.id.archives_transfusion_none) {
            et1.setText("");
            tv1.setHint("输血时间");
            et2.setText("");
            tv2.setHint("输血时间");
            et1.setEnabled(false);
            tv1.setEnabled(false);
            et2.setEnabled(false);
            tv2.setEnabled(false);
        } else {
            et1.setEnabled(true);
            tv1.setEnabled(true);
            et2.setEnabled(true);
            tv2.setEnabled(true);
            et1.setFocusable(true);
            et1.setFocusableInTouchMode(true);
            et1.requestFocus();
        }
    }

    /**
     * 家族病史（父亲）按钮点击事件
     */
    public void onFamilialDiseaseFatherClick(View view) {
        CheckBox none = findViewById(R.id.archives_familial_disease_father_none);
        CheckBox other = findViewById(R.id.archives_familial_disease_father_other);
        EditText otherText = findViewById(R.id.archives_familial_disease_father_other_text);
        View[] views = getViews(findViewById(R.id.archives_familial_disease_father));
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view.getId() == R.id.archives_familial_disease_father_none && cb.getId() != R.id.archives_familial_disease_father_none) {
                    if (none.isChecked()) {
                        cb.setChecked(false);
                        otherText.setText("");
                        otherText.setEnabled(false);
                    }
                } else if (view.getId() != R.id.archives_familial_disease_father_none) {
                    if (cb.isChecked()) {
                        none.setChecked(false);
                    }
                }
            }
        }
        if (flag != true) {
            none.setChecked(true);
        }
        if (other.isChecked()) {
            otherText.setEnabled(true);
            otherText.setFocusable(true);
            otherText.setFocusableInTouchMode(true);
            otherText.requestFocus();
        } else {
            otherText.setText("");
            otherText.setEnabled(false);
        }
    }

    /**
     * 家族病史（母亲）按钮点击事件
     */
    public void onFamilialDiseaseMotherClick(View view) {
        CheckBox none = findViewById(R.id.archives_familial_disease_mother_none);
        CheckBox other = findViewById(R.id.archives_familial_disease_mother_other);
        EditText otherText = findViewById(R.id.archives_familial_disease_mother_other_text);
        View[] views = getViews(findViewById(R.id.archives_familial_disease_mother));
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view.getId() == R.id.archives_familial_disease_mother_none && cb.getId() != R.id.archives_familial_disease_mother_none) {
                    if (none.isChecked()) {
                        cb.setChecked(false);
                        otherText.setText("");
                        otherText.setEnabled(false);
                    }
                } else if (view.getId() != R.id.archives_familial_disease_mother_none) {
                    if (cb.isChecked()) {
                        none.setChecked(false);
                    }
                }
            }
        }
        if (flag != true) {
            none.setChecked(true);
        }
        if (other.isChecked()) {
            otherText.setEnabled(true);
            otherText.setFocusable(true);
            otherText.setFocusableInTouchMode(true);
            otherText.requestFocus();
        } else {
            otherText.setText("");
            otherText.setEnabled(false);
        }
    }

    /**
     * 家族病史（兄弟姐妹）按钮点击事件
     */
    public void onFamilialDiseaseBrotherClick(View view) {
        CheckBox none = findViewById(R.id.archives_familial_disease_brother_none);
        CheckBox other = findViewById(R.id.archives_familial_disease_brother_other);
        EditText otherText = findViewById(R.id.archives_familial_disease_brother_other_text);
        View[] views = getViews(findViewById(R.id.archives_familial_disease_brother));
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view.getId() == R.id.archives_familial_disease_brother_none && cb.getId() != R.id.archives_familial_disease_brother_none) {
                    if (none.isChecked()) {
                        cb.setChecked(false);
                        otherText.setText("");
                        otherText.setEnabled(false);
                    }
                } else if (view.getId() != R.id.archives_familial_disease_brother_none) {
                    if (cb.isChecked()) {
                        none.setChecked(false);
                    }
                }
            }
        }
        if (flag != true) {
            none.setChecked(true);
        }
        if (other.isChecked()) {
            otherText.setEnabled(true);
            otherText.setFocusable(true);
            otherText.setFocusableInTouchMode(true);
            otherText.requestFocus();
        } else {
            otherText.setText("");
            otherText.setEnabled(false);
        }
    }

    /**
     * 家族病史（子女）按钮点击事件
     */
    public void onFamilialDiseaseChildrenClick(View view) {
        CheckBox none = findViewById(R.id.archives_familial_disease_children_none);
        CheckBox other = findViewById(R.id.archives_familial_disease_children_other);
        EditText otherText = findViewById(R.id.archives_familial_disease_children_other_text);
        View[] views = getViews(findViewById(R.id.archives_familial_disease_children));
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view.getId() == R.id.archives_familial_disease_children_none && cb.getId() != R.id.archives_familial_disease_children_none) {
                    if (none.isChecked()) {
                        cb.setChecked(false);
                        otherText.setText("");
                        otherText.setEnabled(false);
                    }
                } else if (view.getId() != R.id.archives_familial_disease_children_none) {
                    if (cb.isChecked()) {
                        none.setChecked(false);
                    }
                }
            }
        }
        if (flag != true) {
            none.setChecked(true);
        }
        if (other.isChecked()) {
            otherText.setEnabled(true);
            otherText.setFocusable(true);
            otherText.setFocusableInTouchMode(true);
            otherText.requestFocus();
        } else {
            otherText.setText("");
            otherText.setEnabled(false);
        }
    }

    /**
     * 遗传病史按钮点击事件
     */
    public void onGeneticDiseaseClick(View view) {
        EditText et = findViewById(R.id.archives_genetic_disease_all_name);
        if (view.getId() == R.id.archives_genetic_disease_all) {
            et.setEnabled(true);
            et.setFocusable(true);
            et.setFocusableInTouchMode(true);
            et.requestFocus();
        } else {
            et.setText("");
            et.setEnabled(false);
        }
    }

    /**
     * 残疾情况按钮点击事件
     */
    public void onDisabilityClick(View view) {
        CheckBox none = findViewById(R.id.archives_disability_none);
        CheckBox other = findViewById(R.id.archives_disability_other);
        EditText otherText = findViewById(R.id.archives_disability_other_text);
        View[] views = getViews(findViewById(R.id.archives_disability));
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view.getId() == R.id.archives_disability_none && cb.getId() != R.id.archives_disability_none) {
                    cb.setChecked(false);
                } else if (view.getId() != R.id.archives_disability_none && cb.getId() == R.id.archives_disability_none) {
                    cb.setChecked(false);
                }
            }
        }
        if (flag != true) {
            none.setChecked(true);
        }
        if (other.isChecked()) {
            otherText.setEnabled(true);
            otherText.setFocusable(true);
            otherText.setFocusableInTouchMode(true);
            otherText.requestFocus();
        } else {
            otherText.setText("");
            otherText.setEnabled(false);
        }
    }

    /**
     * 获取子视图
     */
    private View[] views;

    private View[] getViews(View view) {
        views = new View[0];
        parseView(view);
        return views;
    }

    private void parseView(View view) {
        if (view instanceof ViewGroup) {
            ViewGroup vg = (ViewGroup) view;
            for (int i = 0; i < vg.getChildCount(); i++) {
                View v = vg.getChildAt(i);
                parseView(v);
            }
        } else {
            views = Arrays.copyOf(views, views.length + 1);
            views[views.length - 1] = view;
        }
    }

    /**
     * 从SQLite中读取需提交的数据
     */
    private Map<String, Object> getParams() {
        // 收起列表保证数据全部存入SQLite
        int count = expandableListView.getExpandableListAdapter().getGroupCount();
        for (int i = 0; i < count; i++) {
            expandableListView.collapseGroup(i);
        }

        Map<String, Object> params = new HashMap<>();
        String sfzh = getBasicInfoValues().get("sfzh");
        Cursor cursor = sqLiteHelper.queryByIdCard(new String[]{sfzh});
        if (cursor.moveToFirst()) {
            do {
                for (int i = 1; i < cursor.getColumnCount(); i++) {
                    String name = cursor.getColumnName(i);
                    while (true) {
                        int index = name.indexOf("_");
                        if(index == -1) {
                            break;
                        }
                        name = name.substring(0,index) + name.substring(index + 1, index + 2).toUpperCase() + name.substring(index + 2);
                    }
                    System.out.println("提交的字段名是：" + name);
                    if(name.equals("xqid") || name.equals("xb")|| name.equals("czlx")|| name.equals("mz")|| name.equals("xx")
                        ||name.equals("yx") || name.equals("whcd")|| name.equals("zy")|| name.equals("hyzk")|| name.equals("ss")
                        ||name.equals("ws") || name.equals("sx")|| name.equals("ycbs")|| name.equals("cfpfss")|| name.equals("rllx")
                        || name.equals("ys")|| name.equals("cs")|| name.equals("qcl")){
                        params.put(name, cursor.getInt(i));
                    } else {
                        params.put(name, cursor.getString(i));
                    }

                }
            } while (cursor.moveToNext());
        }
        return params;
    }

    /**
     * 身份证认证接口
     * @param idnumber  身份证号码
     */
    private int getNetIdentify(String idnumber) {
        final int[] code = {-1};
        String token= (String) SpUtils.get(ArchivesActivity.this,"token","");
        int mark= (int) SpUtils.get(ArchivesActivity.this,"mark",1);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("sfzh",idnumber);
        map.put("token",token);
        map.put("mark",mark);
        //idnumber
        OkGo.<String>post(Constant.baseurl+"online/isSigning")
                .upJson((new JSONObject(map)).toString())
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String body = response.body();
                        try {
                            Gson gson=new Gson();
                            IdCardBean bean=gson.fromJson(body, IdCardBean.class);
                            if(bean.getCode()==1||bean.getCode()==3){
                                //直接跳转新增居民档案页面
                                code[0] =0;

                                Map<String, Object> params = getParams();
                                String token = (String) SpUtils.get(ArchivesActivity.this, "token", "");
                                int mark= (int) SpUtils.get(ArchivesActivity.this,"mark",1);
                                int ysid= (int) SpUtils.get(ArchivesActivity.this,"ysid",0);
                                params.put("token", token);
                                params.put("mark",mark);
                                params.put("createBy",ysid);
                                params.put("sfqy",sfqy);//1 签约  0未签约
                                MyLogger.i("添加居民："+(new JSONObject(params)).toString());
                                String uri = Constant.baseurl + "online/user/addResident";
                                OkGo.getInstance().init(getApplication());
                                OkGo.<String>post(uri)
                                        .upJson((new JSONObject(params)).toString())
                                        .execute(new StringCallback() {
                                            @Override
                                            public void onSuccess(Response<String> response) {
                                                dismissLoading();
                                                String body = response.body();
                                                MyLogger.i(body);
                                                Gson gson=new Gson();
                                                DataBean bean=gson.fromJson(body, DataBean.class);
                                                if(bean.getCode()==0){
                                                    Toast.makeText(getApplicationContext(), "信息添加成功！", Toast.LENGTH_LONG).show();
                                                    startActivity(new Intent(ArchivesActivity.this,MainActivity.class));
                                                    finish();
                                                    if(mark==1){
                                                        AppManagerDelegate.getInstance().finishActivity(IdCardActivity.class);
                                                    }else{
                                                        AppManagerDelegate.getInstance().finishActivity(CarteVitalActivity.class);
                                                    }
                                                    AppManagerDelegate.getInstance().finishActivity(SignActivity.class);
                                                }else{
                                                    Toast.makeText(getApplicationContext(),bean.getMsg(), Toast.LENGTH_LONG).show();
                                                }
                                            }

                                            @Override
                                            public void onError(Response<String> response) {
                                                dismissLoading();
                                                Toast.makeText(getApplicationContext(), "服务器暂时无法访问，稍后再试！", Toast.LENGTH_LONG).show();
                                            }
                                        });
                            }else if(bean.getCode()==2){
                                Toast.makeText(getApplicationContext(), "您已经添加过该居民了", Toast.LENGTH_LONG).show();
                            }
                            else{
                                Toast.makeText(getApplicationContext(), "服务器暂时无法访问，稍后再试！", Toast.LENGTH_LONG).show();
        }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    @Override
                    public void onError(Response<String> response) {
                        Toast.makeText(getApplicationContext(), "服务器暂时无法访问，稍后再试！", Toast.LENGTH_LONG).show();
                    }
                });
        return  code[0];
    }
    /**
     * 提交数据
     */
    public void onClickSubmit(View view) {
        if (checkBasicInfoIsError()) {
            return;
        }
        int count = expandableListView.getExpandableListAdapter().getGroupCount();
        for (int i = 0; i < count; i++) {
            expandableListView.collapseGroup(i);
        }
        if (LastClickUtils.isLastClick("点击的太快了")) {
            showLoading();
            checkPhone(mPhone);
        }


       // int code=getNetIdentify(id_number);
//        if(code==0){
//
//        }else{
//            Toast.makeText(getApplicationContext(), "您已经添加过该居民了", Toast.LENGTH_LONG).show();
//        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ib_back:
                finish();
                break;
        }
    }
    //民族点击事件
    public void onNation(View view) {
        TextView textView = view.findViewById(R.id.tv_nation);
        new MaterialDialog.Builder(this)
            .title("民族")
            .positiveText("确认")
            .items(R.array.nation_archives)
            .itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    if (!TextUtils.isEmpty(text)) {
                        textView.setText(text);

                    }

                    return true;
                }
            })
            .show();


    }
}
